<?php
/**
 * Fructa functions and definitions.
 *
 * Sets up the theme and provides some helper functions, which are used
 * in the theme as custom template tags. Others are attached to action and
 * filter hooks in WordPress to change core functionality.
 *
 * For more information on hooks, actions, and filters, see http://codex.wordpress.org/Plugin_API.
 *
* @package fructa
* @since fructa 1.0
 */
function register_my_menus() {
	register_nav_menus(
		array(
			'pages-menu' => __( 'Pages Menu' )
			)
		);
}
add_action( 'init', 'register_my_menus' );
add_theme_support( 'post-thumbnails' ); 

function my_wp_nav_menu_args( $args = '' ) {
	$args['container'] = false;
	return $args;
}
add_filter( 'wp_nav_menu_args', 'my_wp_nav_menu_args' );

add_filter('nav_menu_css_class' , 'special_nav_class' , 10 , 2);

function special_nav_class($classes, $item){
     if( in_array('current-menu-item', $classes) ){
             $classes[] = 'active ';
     }
     return $classes;
}

if ( ! function_exists( 'post_is_in_descendant_category' ) ) {
	function post_is_in_descendant_category( $cats, $_post = null ) {
		foreach ( (array) $cats as $cat ) {
			// get_term_children() accepts integer ID only
			$descendants = get_term_children( (int) $cat, 'category' );
			if ( $descendants && in_category( $descendants, $_post ) )
				return true;
		}
		return false;
	}
}

function my_theme_add_editor_styles() {
    global $post;
   	$template = str_replace (".php","", get_page_template_slug($post->ID));
    $editor_style = 'editor-style-' . $template . '.css';
    add_editor_style( $editor_style );
}

add_action( 'pre_get_posts', 'my_theme_add_editor_styles' );
add_post_type_support('page', 'excerpt');
?>